/**
 * fileName:com.zimo.web.mapper.UserMapper.java
 * projectName:Zimo
 */
package com.zimo.web.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import com.zimo.web.entity.User;

/**
 * 用户信息数据层
 * @author sg.z/2013-12-18/下午5:52:16
 */
@Repository(value="userMapper")
public interface UserMapper {

	final String TABLE_NAME = "user";
	
	final String INSERT_SQL = "insert into "+TABLE_NAME+" (user_name,user_pass,user_email,head_url) values (#{user.userName},#{user.userPass},#{user.userEmail},#{user.headUrl})";
	final String SELECT_BY_NAME_PASS = "select * from user where user_name=#{name} and user_pass=#{pass}";
	final String SELECT_BY_NAME = "select * from user where user_name=#{userName} ";
	final String SELECT_BY_EMAIL = "select * from user where user_email=#{userEmail} ";
	/**
	 * 插入用户
	 *
	 * @author sg/2013-12-18/下午6:07:28
	 */
	@Insert(INSERT_SQL)
	@Options(flushCache=true,timeout=20000)
	public void insertUser(@Param("user") User user);
	
	/**
	 * 
	 * description :   根据用户名和密码查询用户
	 * @return User
	 * @param user
	 * @return
	 * @author sg/2013-12-25/上午10:50:25
	 */
	@Select(SELECT_BY_NAME_PASS)
	@Results(value={@Result(property="userName",column="user_name"),@Result(property="headUrl",column="head_url"),@Result(property="isAdmin",column="is_admin")})
	public User getUserByNameAndPass(@Param("name") String userName,@Param("pass") String userPass);
	
	/**
	 * 根据用户名查找用户信息
	 * @return User
	 * @param userName
	 * @return
	 * @author sg/2013-12-25/上午11:19:33
	 */
	@Select(SELECT_BY_NAME)
	@Results(value={@Result(property="userName",column="user_name"),@Result(property="headUrl",column="head_url"),@Result(property="isAdmin",column="is_admin")})
	public User getUserByName(@Param("userName") String userName);
	
	/**
	 * 根据邮箱查找用户信息
	 * @return User
	 * @param userEmail
	 * @return
	 * @author sg/2013-12-25/上午11:19:51
	 */
	@Select(SELECT_BY_EMAIL)
	@Results(value={@Result(property="userName",column="user_name"),@Result(property="headUrl",column="head_url"),@Result(property="isAdmin",column="is_admin")})
	public User getUserByEmail(@Param("userEmail") String userEmail);
	
}
